package com.fenghongzhang.day007valueanim;

import androidx.appcompat.app.AppCompatActivity;

import android.animation.Animator;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.animation.AnimationSet;
import android.view.animation.BounceInterpolator;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {
    private Button btn;
    private static final String TAG = "MainActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        btn = (Button) findViewById(R.id.btn);

    }
    public void btn(View view) {

//        test();

//        new AnimationSet()
        AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.setDuration(2000);
        ObjectAnimator animatorx = ObjectAnimator.ofFloat(btn, "scaleX", 1, 2);
        ObjectAnimator animatory = ObjectAnimator.ofFloat(btn, "scaleY", 1, 2);

//        animatorSet.play(animatorx).with(animatory);
//        animatorSet.playTogether(animatorx,animatory);
//        animatorSet.play(animatorx).before(animatory);

        animatorSet.playSequentially(animatorx,animatory);

        animatorSet.start();


    }

    private void test() {
        ValueAnimator valueAnimator = ValueAnimator.ofInt(btn.getWidth(), 500);

        valueAnimator.setDuration(2000);
//        valueAnimator.setRepeatCount();
//        valueAnimator.setInterpolator(new BounceInterpolator());
//        valueAnimator.setRepeatMode();
        valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                int animatedValue = (int) animation.getAnimatedValue();
                Log.i(TAG, "onAnimationUpdate: "+animatedValue);
                btn.setWidth(animatedValue);
//                btn.getLayoutParams().width = animatedValue;
//                btn.requestLayout();
            }
        });
        valueAnimator.start();
    }
}
